//
// Created by xili on 2024/8/13 17:17.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    string clearDigits(string s) {
        stack<char> sk;
        for (auto &item: s) {
            if (isdigit(item) && !sk.empty() && !isdigit(sk.top())) {
                sk.pop();
            } else {
                sk.push(item);
            }
        }
        string ans;
        while (!sk.empty()) {
            ans.push_back(sk.top());
            sk.pop();
        }
        reverse(ans.begin(), ans.end());
        return ans;
    }
};